package com.news.gpb.dao;

import com.news.gpb.entity.Coll;
import com.news.gpb.entity.Like;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.Collection;
import java.util.List;

@Repository
public interface CollectDao {

    @Select("select * from collection where user_id=#{coll.user_id} and news_id=#{coll.news_id}")
    Integer getCollect(@Param("coll") Coll coll);

    @Insert("insert into collection (user_id,news_id) values(#{coll.user_id},#{coll.news_id})")
    @Options(useGeneratedKeys = true,keyProperty = "coll.collect_id",keyColumn = "collect_id")
    Integer collectUp(@Param("coll") Coll coll);

    @Delete("delete from collection where user_id=#{coll.user_id} and news_id=#{coll.news_id}")
    Integer collectDown(@Param("coll") Coll coll);

    @Select("select count(*) from collection where user_id=#{user_id}")
    Integer countCollect(@Param("user_id") int user_id);

    @Select("select news_id from collection where user_id=#{user_id} order by collect_time desc")
    List<Integer> getMyCollect(@Param("user_id")int user_id);
}
